# 生成一个每个元素均为[0-255]均匀分布的2行3列随机张量
img = torch.randint(0,255,(2,3,2,3)) #(B,C,H,W)
img = torch.as_tensor(img,dtype=torch.float32)
print("img:",img)
bn  = nn.BatchNorm2d(num_features=3,# 参数3表示特征通道数
                        eps=1e-5,# 默认为1e-5
                        momentum= 0.1,# 默认为0.1
                        affine= True,# 默认为True
                        track_running_stats = True# 默认为True
                       ) 
# 输出初始的模型存储值
print('running mean:',bn.running_mean, 'running var:',bn.running_var)
# 转化为训练阶段
bn.train()
img_t1 = bn(img)
print("img_t1:")
print(img_t1)
print('一次迭代更新running mean:',bn.running_mean,'running var:',bn.running_var)
img_t2=bn(img)
print("img_t2:", img_t2)
print('二次迭代更新running mean:',bn.running_mean,'running var:',bn.running_var)
